﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using LuxsanTool.Tool.Judge;
using System.Windows.Forms.DataVisualization.Charting;
using LuxsanTool.Tool;
using LuxsanBaseHelpLib;
using ScriptEditor;
namespace LuxsanTool
{

    public class InstanceStationWork : StationWork
    {
        public static readonly object uniqueLock = new object();

        static Mutex mutex = new Mutex();

        #region Register 注册工具
        /// <summary>
        /// 初始化 添加用到的MES工具   将工站添加到机器管理上
        /// </summary>
        public override void Initial()
        {
            //List<string> listKeys = m_mesBsaeTool.Keys.ToList();
            //List<LuxsanTool.Tool.BaseTool> listTool = m_mesBsaeTool.Values.ToList();
            //LuxsanTool.UserControl_Log m_UserControl_Log = new UserControl_Log("工站的运行记录");
            m_UserControl_Log = new LuxsanTool.UserControl_Log(strStationName+ "运行记录");
            //加载工站
            if(strStationName.Contains("心跳"))
            {

            }
            LoadTool();
        }
        #endregion

        #region  Realse 释放资源
        /// <summary>
        /// 释放资源
        /// </summary>
        public override void Realse()
        {
            List<string> listKeys = m_mesBaseTool.Keys.ToList();
            for (int i = 0; i < listKeys.Count; i++)
            {
                m_mesBaseTool[listKeys[i]].Realse();
            }
        }
        #endregion

        #region SaveTool  保存工具
        /// <summary>
        /// 保存工具
        /// </summary>
        public void SaveTool(string _strCurstationName, LuxsanToolDelegate _luxsanToolDelegate, LuxsanToolAlarmDelegate _LuxsanToolAlarmDelegate)
        {
            if (!(System.IO.Directory.Exists(m_strFilePath)))
                System.IO.Directory.CreateDirectory(m_strFilePath);

            //if (System.IO.File.Exists(strFilePath + "\\Tool.ini"))
            //    System.IO.File.Delete(strFilePath + "\\Tool.ini");

            List<string> listKeys = m_mesBaseTool.Keys.ToList();
            List<LuxsanTool.Tool.BaseTool> listTool = m_mesBaseTool.Values.ToList();

            m_iniFile.WtiteString(strStationName + "_ToolCount", "Count", listTool.Count.ToString(), m_strFilePath + "\\" + strStationName + "\\Tool.ini");


                    for (int i = 0; i < listTool.Count; i++)
                    {
                        m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "ToolName", listTool[i].m_strToolName.ToString(), m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                        m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "Enable", listTool[i].m_bEnable.ToString(), m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                        m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "EditId", listTool[i].m_EditId.ToString(), m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                        listTool[i].SavePara();

                        if (listTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具 &&
                           _strCurstationName == listTool[i].m_strStationName)
                        {
                         string strError = "";
                         LuxsanTool.Tool.BaseTool other1BaseTool = m_ScriptFactory[listTool[i].m_strToolName].CreateInstanceWithDll(m_strFilePath,listTool[i].m_strStationName, listTool[i].m_strToolName,out strError);
                        // m_ScriptFactory[listTool[i].m_strToolName].SaveTxt_Copy(m_strFilePath, listTool[i].m_strStationName, listTool[i].m_strToolName, m_ScriptFactory[listTool[i].m_strToolName].m_strScriptTxt);
                        if (strError=="Sucess")
                        {
                           other1BaseTool.m_strToolName = listTool[i].m_strToolName;
                           other1BaseTool.m_bEnable = bEnable;
                           other1BaseTool.m_strStationName = strStationName;
                           other1BaseTool.SetFilePath(m_strFilePath);
                           other1BaseTool.Initial();
                            other1BaseTool.bSingleRun = true;
                           //other1BaseTool.AssistToolOutPutValue();
                           //other1BaseTool.RunTool();
                           //other1BaseTool.m_UserControl_Other1Tool.OutPutValueParaToForm();
                           other1BaseTool.bSingleRun = false;
                           //_other1BaseTool.DisRunResult();
                           //LuxsanTool.Tool.Other1BaseTool other1Tool  baseTool = scriptFactory.m_other1BaseTool;

                           other1BaseTool.m_LuxsanToolDelegate = _luxsanToolDelegate;
                           other1BaseTool.m_LuxsanToolAlarmDelegate = _LuxsanToolAlarmDelegate;
                           m_mesBaseTool[listTool[i].m_strToolName] = other1BaseTool;
                           LuxsanTool.Tool.Other1BaseTool other1Tool = (LuxsanTool.Tool.Other1BaseTool)m_mesBaseTool[listTool[i].m_strToolName];
                           other1Tool.bSingleRun = true;
                           //other1Tool.RunTool();
                           other1Tool.m_UserControl_Other1Tool.OutPutValueParaToForm();
                           other1Tool.bSingleRun = false;
                           other1Tool.DisRunResult();
                           luxsanStationWorkDelegate("Script", listTool[i].m_strLogName, listTool[i].m_strStationName, "");
                         }
                        }
                    }
        
        }
        #endregion

        #region  LoadTool 加载工具
        /// <summary>
        /// LoadTool 加载工具
        /// </summary>
        public void LoadTool()
        {
            if (!(System.IO.Directory.Exists(m_strFilePath)))
                System.IO.Directory.CreateDirectory(m_strFilePath);

            int iCount = m_iniFile.GetInt(strStationName + "_ToolCount", "Count", m_strFilePath + "\\" + strStationName + "\\Tool.ini");

            for (int i = 0; i < iCount; i++)
            {
                string strToolName = m_iniFile.GetString(strStationName + "_Tool_" + i.ToString(), "ToolName", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                bEnable = (m_iniFile.GetBool(strStationName + "_Tool_" + i.ToString(), false, "Enable", m_strFilePath + "\\" + strStationName + "\\Tool.ini"));
                int iEditId = m_iniFile.GetInt(strStationName + "_Tool_" + i.ToString(), "EditId", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                LuxsanTool.Tool.BaseTool baseTool = null;
                //脚本编辑单独拉出
                ScriptFactory scriptFactory = new ScriptFactory();
                baseTool = NewTool(iEditId, strStationName, strToolName,out scriptFactory);
                //baseTool.Initial();
                AddTool(strToolName, baseTool, scriptFactory);
            }
        }
        #endregion

        #region SaveTool  保存工具
        ///// <summary>
        ///// 保存工具
        ///// </summary>
        //public void SaveTool(string _stationName, LuxsanToolDelegate _luxsanToolDelegate, LuxsanToolAlarmDelegate _LuxsanToolAlarmDelegate)
        //{
        //    if (!(System.IO.Directory.Exists(m_strFilePath)))
        //        System.IO.Directory.CreateDirectory(m_strFilePath);

        //    //if (System.IO.File.Exists(strFilePath + "\\Tool.ini"))
        //    //    System.IO.File.Delete(strFilePath + "\\Tool.ini");

        //    List<string> listKeys = m_mesBaseTool.Keys.ToList();
        //    List<LuxsanTool.Tool.BaseTool> listTool = m_mesBaseTool.Values.ToList();

        //    m_iniFile.WtiteString(strStationName + "_ToolCount", "Count", listTool.Count.ToString(), m_strFilePath  + "\\Tool.ini");

        //    Task.Run(() =>
        //    {

        //        LuxsanProjectManage.Global.GetMainForm().Invoke(new MethodInvoker(delegate
        //        {
        //        for (int i = 0; i < listTool.Count; i++)
        //        {
        //            m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "ToolName", listTool[i].m_strToolName.ToString(), m_strFilePath + "\\Tool.ini");
        //            m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "Enable", listTool[i].m_bEnable.ToString(), m_strFilePath  + "\\Tool.ini");
        //            m_iniFile.WtiteString(strStationName + "_Tool_" + i.ToString(), "EditId", listTool[i].m_EditId.ToString(), m_strFilePath  + "\\Tool.ini");
        //            listTool[i].SavePara();

        //            if (listTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具 &&
        //            _stationName == listTool[i].m_strStationName)
        //            {
        //                    bool bBuild = false;
        //                    m_ScriptFactory[listTool[i].m_strToolName].m_frmScriptEditor.SaveScriptFile(m_strFilePath, listTool[i].m_strStationName, listTool[i].m_strToolName);

        //                    ScriptFactory scriptFactory = new ScriptFactory();
        //                    LuxsanTool.Tool.BaseTool baseTool = null;
        //                    bBuild= scriptFactory.BuildScript(m_strFilePath, listTool[i].m_strStationName, listTool[i].m_strToolName);

        //                    if (bBuild)
        //                    {

        //                        scriptFactory.m_other1BaseTool.m_strToolName = listTool[i].m_strToolName;
        //                        scriptFactory.m_other1BaseTool.m_bEnable = bEnable;
        //                        scriptFactory.m_other1BaseTool.m_strStationName = strStationName;
        //                        scriptFactory.m_other1BaseTool.SetFilePath(m_strFilePath);
        //                        scriptFactory.m_other1BaseTool.Initial();
        //                        scriptFactory.m_other1BaseTool.bSingleRun = true;
        //                        //_scriptFactory.m_other1BaseTool.AssistToolOutPutValue();
        //                        //scriptFactory.m_other1BaseTool.RunTool();
        //                        //_scriptFactory.m_other1BaseTool.m_UserControl_Other1Tool.OutPutValueParaToForm();
        //                        scriptFactory.m_other1BaseTool.bSingleRun = false;
        //                        //_scriptFactory.m_other1BaseTool.DisRunResult();
        //                        //LuxsanTool.Tool.Other1BaseTool other1Tool  baseTool = scriptFactory.m_other1BaseTool;

        //                        scriptFactory.m_other1BaseTool.m_LuxsanToolDelegate = _luxsanToolDelegate;
        //                        scriptFactory.m_other1BaseTool.m_LuxsanToolAlarmDelegate = _LuxsanToolAlarmDelegate;
        //                        //m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool.m_strToolName = listTool[i].m_strToolName;
        //                        //m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool.m_bEnable = bEnable;
        //                        //m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool.m_strStationName = listTool[i].m_strStationName;
        //                        //m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool.SetFilePath(m_strFilePath);
        //                        //m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool.Initial();
        //                        m_mesBaseTool[listTool[i].m_strToolName]=scriptFactory.m_other1BaseTool;
        //                        m_ScriptFactory[listTool[i].m_strToolName] = scriptFactory;
        //                        //m_mesBaseTool[listTool[i].m_strToolName] = m_ScriptFactory[listTool[i].m_strToolName].m_other1BaseTool;
        //                        LuxsanTool.Tool.Other1BaseTool other1Tool = (LuxsanTool.Tool.Other1BaseTool)m_mesBaseTool[listTool[i].m_strToolName];
        //                        other1Tool.bSingleRun = true;
        //                        //other1Tool.RunTool();

        //                        other1Tool.m_UserControl_Other1Tool.OutPutValueParaToForm();
        //                        other1Tool.bSingleRun = false;
        //                        other1Tool.DisRunResult();

        //                        luxsanStationWorkDelegate("Script", listTool[i].m_strLogName, listTool[i].m_strStationName, "");
        //                    }

        //            }
        //        } 
        //        }));
        //    });
        //}
        #endregion

        #region  LoadTool 加载工具
        ///// <summary>
        ///// LoadTool 加载工具
        ///// </summary>
        //public void LoadTool()
        //{
        //    if (!(System.IO.Directory.Exists(m_strFilePath)))
        //        System.IO.Directory.CreateDirectory(m_strFilePath);

        //    int iCount = m_iniFile.GetInt(strStationName + "_ToolCount", "Count", m_strFilePath  + "\\Tool.ini");

        //    for (int i = 0; i < iCount; i++)
        //    {
        //        string strToolName = m_iniFile.GetString(strStationName + "_Tool_" + i.ToString(), "ToolName", m_strFilePath  + "\\Tool.ini");

        //        bEnable =(m_iniFile.GetBool(strStationName + "_Tool_" + i.ToString(),false, "Enable", m_strFilePath  + "\\Tool.ini"));


        //        int iEditId = m_iniFile.GetInt(strStationName + "_Tool_" + i.ToString(), "EditId", m_strFilePath  + "\\Tool.ini");

        //        LuxsanTool.Tool.BaseTool baseTool = null;

        //        //脚本编辑单独拉出
        //        ScriptFactory scriptFactory = new ScriptFactory();
        //        baseTool = NewTool(iEditId, strStationName, strToolName,out scriptFactory);
        //        //baseTool.Initial();
        //        AddTool(strToolName, baseTool, scriptFactory);
        //    }
        //}
        #endregion

        #region  CopyTool 复制工具
        /// <summary>
        /// CopyTool 复制工具
        /// </summary>
        public Tool.BaseTool CopyTool(string _strStationName,string _strToolNmae,out ScriptFactory _scriptFactory)
        {
            LuxsanTool.Tool.BaseTool baseTool = null;
           
            if (!(System.IO.Directory.Exists(m_strFilePath)))
                System.IO.Directory.CreateDirectory(m_strFilePath);

            int iCount = m_iniFile.GetInt(strStationName + "_ToolCount", "Count", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
            _scriptFactory = null;
            for (int i = 0; i < iCount; i++)
            {
                string strToolName = m_iniFile.GetString(strStationName + "_Tool_" + i.ToString(), "ToolName", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                 bEnable =m_iniFile.GetBool(strStationName + "_Tool_" + i.ToString(), false,"Enable", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                int iEditId = m_iniFile.GetInt(strStationName + "_Tool_" + i.ToString(), "EditId", m_strFilePath + "\\" + strStationName + "\\Tool.ini");
                if (_strStationName == strStationName&& _strToolNmae==strToolName)
                {
                    _scriptFactory = new ScriptFactory();
                    baseTool = NewTool(iEditId, strStationName, strToolName,out _scriptFactory);
                    baseTool.m_strToolName = _strToolNmae + "_Copy";
                    baseTool.m_strStationName = _strStationName;
                    bool bError;
                   // _scriptFactory.m_strScriptTxt = _scriptFactory.LoadTxt_Copy(m_strFilePath, strStationName, strToolName, out bError);
                    if (iEditId == (int)Tool.ToolEnum.ToolEditEnum.脚本编辑工具)
                    {
                        _scriptFactory.m_strToolName = _strToolNmae + "_Copy";
                        _scriptFactory.m_strStationName = _strStationName;
                    }
                }
            }

            return baseTool;
        }
        #endregion


        #region NewTool 新建工具
        /// <summary>
        /// 新建工具 
        /// </summary>
        /// <param name="_iEditId"></param>
        /// <param name="_strToolName"></param>
        /// <returns></returns>
        public LuxsanTool.Tool.BaseTool NewTool(int _iEditId, string _strStationName, string _strToolName,out ScriptFactory _scriptFactory)
        {
            LuxsanTool.Tool.BaseTool baseTool = null;
            _scriptFactory = new ScriptFactory();
            switch (_iEditId)
            {
                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.MES工具:
                    LuxsanTool.Tool.MesTool mesTool = new LuxsanTool.Tool.MesTool(_strToolName);
                    mesTool.m_strToolName = _strToolName;
                    mesTool.m_bEnable = bEnable;
                    mesTool.m_strStationName = _strStationName;
                    mesTool.SetFilePath(m_strFilePath);
                    mesTool.Initial();
                    mesTool.bSingleRun = true;
                    //mesTool.RunTool();
                    mesTool.bSingleRun = false;
                    baseTool = mesTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.PDCA工具:
                    LuxsanTool.Tool.PDCATool pDCATool = new LuxsanTool.Tool.PDCATool(_strToolName);
                    pDCATool.m_strToolName = _strToolName;
                    pDCATool.m_bEnable = bEnable;
                    pDCATool.m_strStationName = _strStationName;
                    pDCATool.SetFilePath(m_strFilePath);
                    pDCATool.Initial();
                    pDCATool.bSingleRun = true;
                    //pDCATool.RunTool();
                    pDCATool.bSingleRun = false;
                    baseTool = pDCATool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.HIVE工具:
                    LuxsanTool.Tool.HiveTool hiveTool = new LuxsanTool.Tool.HiveTool(_strToolName);
                    hiveTool.m_strToolName = _strToolName;
                    hiveTool.m_bEnable = bEnable;
                    hiveTool.m_strStationName = _strStationName;
                    hiveTool.SetFilePath(m_strFilePath);
                    hiveTool.Initial();
                    hiveTool.bSingleRun = true;
                    //hiveTool.RunTool();
                    hiveTool.bSingleRun = false;
                    baseTool = hiveTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取通讯值工具:
                    LuxsanTool.Tool.ComReadValueTool comReadValueTool = new LuxsanTool.Tool.ComReadValueTool(_strToolName);
                    comReadValueTool.m_strToolName = _strToolName;
                    comReadValueTool.m_bEnable = bEnable;
                    comReadValueTool.m_strStationName = _strStationName;
                    comReadValueTool.SetFilePath(m_strFilePath);
                    comReadValueTool.Initial();
                    comReadValueTool.bSingleRun = true;
                    //comReadValueTool.RunTool();
                    comReadValueTool.bSingleRun = false;
                    baseTool = comReadValueTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入通讯值工具:
                    LuxsanTool.Tool.ComWriteValueTool comWriteValueTool = new LuxsanTool.Tool.ComWriteValueTool(_strToolName);
                    comWriteValueTool.m_strToolName = _strToolName;
                    comWriteValueTool.m_bEnable = bEnable;
                    comWriteValueTool.m_strStationName = _strStationName;
                    comWriteValueTool.SetFilePath(m_strFilePath);
                    comWriteValueTool.Initial();
                    comWriteValueTool.bSingleRun = true;
                    //comWriteValueTool.RunTool();
                    comWriteValueTool.bSingleRun = false;
                    baseTool = comWriteValueTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取PLC寄存器值工具:
                    LuxsanTool.Tool.PLCReadValueTool pLCReadValueTool = new LuxsanTool.Tool.PLCReadValueTool(_strToolName);
                    pLCReadValueTool.m_strToolName = _strToolName;
                    pLCReadValueTool.m_bEnable = bEnable;
                    pLCReadValueTool.m_strStationName = _strStationName;
                    pLCReadValueTool.SetFilePath(m_strFilePath);
                    pLCReadValueTool.Initial();
                    pLCReadValueTool.bSingleRun = true;
                    //pLCReadValueTool.RunTool();
                    pLCReadValueTool.bSingleRun = false;
                    baseTool = pLCReadValueTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入PLC寄存器值工具:
                    LuxsanTool.Tool.PLCWriteValueTool pLCWriteValueTool = new LuxsanTool.Tool.PLCWriteValueTool(_strToolName);
                    pLCWriteValueTool.m_strToolName = _strToolName;
                    pLCWriteValueTool.m_bEnable = bEnable;
                    pLCWriteValueTool.m_strStationName = _strStationName;
                    pLCWriteValueTool.SetFilePath(m_strFilePath);
                    pLCWriteValueTool.Initial();
                    pLCWriteValueTool.bSingleRun = true;
                    //pLCWriteValueTool.RunTool();
                    pLCWriteValueTool.bSingleRun = false;
                    baseTool = pLCWriteValueTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.判断工具:
                    LuxsanTool.Tool.JudgeTool ifTool = new LuxsanTool.Tool.JudgeTool(_strToolName);
                    ifTool.m_strToolName = _strToolName;
                    ifTool.m_bEnable = bEnable;
                    ifTool.m_strStationName = _strStationName;
                    ifTool.SetFilePath(m_strFilePath);
                    ifTool.Initial();
                    ifTool.bSingleRun = true;
                    ifTool.RunTool();
                    ifTool.bSingleRun = false;
                    baseTool = ifTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.图表显示工具:
                    LuxsanTool.Tool.ChartTool chartTool = new LuxsanTool.Tool.ChartTool(_strToolName);
                    chartTool.m_strToolName = _strToolName;
                    chartTool.m_bEnable = bEnable;
                    chartTool.m_strStationName = _strStationName;
                    chartTool.SetFilePath(m_strFilePath);
                    chartTool.Initial();
                    chartTool.bSingleRun = true;
                    //chartTool.RunTool():
                    chartTool.bSingleRun = false;
                    baseTool = chartTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.字符操作工具:
                    LuxsanTool.Tool.StrSpiltTool strSpiltTool = new LuxsanTool.Tool.StrSpiltTool(_strToolName);
                    strSpiltTool.m_strToolName = _strToolName;
                    strSpiltTool.m_bEnable = bEnable;
                    strSpiltTool.m_strStationName = _strStationName;
                    strSpiltTool.SetFilePath(m_strFilePath);
                    strSpiltTool.Initial();
                    strSpiltTool.bSingleRun = true;
                    //strSpiltTool.RunTool();
                    strSpiltTool.bSingleRun = false;
                    baseTool = strSpiltTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.获取数组值工具:
                    LuxsanTool.Tool.ArraryContentTool arraryContentTool = new LuxsanTool.Tool.ArraryContentTool(_strToolName);
                    arraryContentTool.m_strToolName = _strToolName;
                    arraryContentTool.m_bEnable = bEnable;
                    arraryContentTool.m_strStationName = _strStationName;
                    arraryContentTool.SetFilePath(m_strFilePath);
                    arraryContentTool.Initial();
                    arraryContentTool.bSingleRun = true;
                    //arraryContentTool.RunTool();
                    arraryContentTool.bSingleRun = false;
                    baseTool = arraryContentTool;

                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.定义变量工具:
                    LuxsanTool.Tool.InstanceVarTool instanceVarTool = new LuxsanTool.Tool.InstanceVarTool(_strToolName);
                    instanceVarTool.m_strToolName = _strToolName;
                    instanceVarTool.m_bEnable = bEnable;
                    instanceVarTool.m_strStationName = _strStationName;
                    instanceVarTool.SetFilePath(m_strFilePath);
                    instanceVarTool.Initial();
                    instanceVarTool.bSingleRun = true;
                    instanceVarTool.RunTool();
                    instanceVarTool.bSingleRun = false;
                    baseTool = instanceVarTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.文件操作工具:
                    LuxsanTool.Tool.SaveCsvTool saveCsvTool = new LuxsanTool.Tool.SaveCsvTool(_strToolName);
                    saveCsvTool.m_strToolName = _strToolName;
                    saveCsvTool.m_bEnable = bEnable;
                    saveCsvTool.m_strStationName = _strStationName;
                    saveCsvTool.SetFilePath(m_strFilePath);
                    saveCsvTool.Initial();
                    saveCsvTool.bSingleRun = true;
                    //saveCsvTool.RunTool();
                    saveCsvTool.bSingleRun = false;
                    baseTool = saveCsvTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入数据库工具:
                    LuxsanTool.Tool.WriteDataBaseTool writeDataBaseTool = new LuxsanTool.Tool.WriteDataBaseTool(_strToolName);
                    writeDataBaseTool.m_strToolName = _strToolName;
                    writeDataBaseTool.m_bEnable = bEnable;
                    writeDataBaseTool.m_strStationName = _strStationName;
                    writeDataBaseTool.SetFilePath(m_strFilePath);
                    writeDataBaseTool.Initial();
                    writeDataBaseTool.bSingleRun = true;
                  
                    //writeDataBaseTool.RunTool();
                    writeDataBaseTool.bSingleRun = false;
                    baseTool = writeDataBaseTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取数据库工具:
                    LuxsanTool.Tool.ReadDataBaseTool readDataBaseBool = new LuxsanTool.Tool.ReadDataBaseTool(_strToolName);
                    readDataBaseBool.m_strToolName = _strToolName;
                    readDataBaseBool.m_bEnable = bEnable;
                    readDataBaseBool.m_strStationName = _strStationName;
                    readDataBaseBool.SetFilePath(m_strFilePath);
                    readDataBaseBool.Initial();
                    readDataBaseBool.bSingleRun = true;
                    //readDataBaseBool.RunTool();
                    readDataBaseBool.bSingleRun = false;
                    baseTool = readDataBaseBool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行状态工具:
                    LuxsanTool.Tool.RunStateTool runStateTool = new LuxsanTool.Tool.RunStateTool(_strToolName);
                    runStateTool.m_strToolName = _strToolName;
                    runStateTool.m_bEnable = bEnable;
                    runStateTool.m_strStationName = _strStationName;
                    runStateTool.SetFilePath(m_strFilePath);
                    runStateTool.Initial();
                    runStateTool.bSingleRun = true;
                    //runStateTool.RunTool();
                    runStateTool.bSingleRun = false;
                    baseTool = runStateTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行模式工具:
                    LuxsanTool.Tool.RunModeTool runModeTool = new LuxsanTool.Tool.RunModeTool(_strToolName);
                    runModeTool.m_strToolName = _strToolName;
                    runModeTool.m_bEnable = bEnable;
                    runModeTool.m_strStationName = _strStationName;
                    runModeTool.SetFilePath(m_strFilePath);
                    runModeTool.Initial();
                    runModeTool.bSingleRun = true;
                    //runModeTool.RunTool();
                    runModeTool.bSingleRun = false;
                    baseTool = runModeTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.赋值变量工具:
                    LuxsanTool.Tool.ValuationTool valuationTool = new LuxsanTool.Tool.ValuationTool(_strToolName);
                    valuationTool.m_strToolName = _strToolName;
                    valuationTool.m_bEnable = bEnable;
                    valuationTool.m_strStationName = _strStationName;
                    valuationTool.SetFilePath(m_strFilePath);
                    valuationTool.Initial();
                    valuationTool.bSingleRun = true;
                    //valuationTool.RunTool();
                    valuationTool.bSingleRun = false;
                    baseTool = valuationTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Atlas数据工具:
                    LuxsanTool.Tool.AtlasTool atlasTool = new LuxsanTool.Tool.AtlasTool(_strToolName);
                    atlasTool.m_strToolName = _strToolName;
                    atlasTool.m_bEnable = bEnable;
                    atlasTool.m_strStationName = _strStationName;
                    atlasTool.SetFilePath(m_strFilePath);
                    atlasTool.Initial();
                    atlasTool.bSingleRun = true;
                    //atlasTool.RunTool();
                    atlasTool.bSingleRun = false;
                    baseTool = atlasTool;
                    break;

                //case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.HiveErrorData:
                //    LuxsanTool.Tool.HiveErrorDataTool errorData = new LuxsanTool.Tool.HiveErrorDataTool(_strToolName);
                //    errorData.m_strToolName = _strToolName;
                //    errorData.m_bEnable = bEnable;
                //    errorData.m_strStationName = _strStationName;
                //    errorData.Initial();
                //    baseTool = errorData;
                //    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.Hive汇总工具:
                    LuxsanTool.Tool.HiveAllTool machineSate = new LuxsanTool.Tool.HiveAllTool(_strToolName);
                    machineSate.m_strToolName = _strToolName;
                    machineSate.m_bEnable = bEnable;
                    machineSate.m_strStationName = _strStationName;
                    machineSate.SetFilePath(m_strFilePath);
                    machineSate.Initial();
                    machineSate.bSingleRun = true;
                    //machineSate.RunTool();
                    machineSate.bSingleRun = false;
                    baseTool = machineSate;
                    break;
                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.产能显示工具:
                    LuxsanTool.Tool.ProductTool productTool = new LuxsanTool.Tool.ProductTool(_strToolName);
                    productTool.m_strToolName = _strToolName;
                    productTool.m_bEnable = bEnable;
                    productTool.m_strStationName = _strStationName;
                    productTool.SetFilePath(m_strFilePath);
                    productTool.Initial();
                    productTool.bSingleRun = true;
                    //productTool.RunTool();
                    productTool.bSingleRun = false;
                    baseTool = productTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.逻辑运算工具:
                    LuxsanTool.Tool.CalculusTool calculusTool = new LuxsanTool.Tool.CalculusTool(_strToolName);
                    calculusTool.m_strToolName = _strToolName;
                    calculusTool.m_bEnable = bEnable;
                    calculusTool.m_strStationName = _strStationName;
                    calculusTool.SetFilePath(m_strFilePath);
                    calculusTool.Initial();
                    calculusTool.bSingleRun = true;
                    //calculusTool.RunTool();
                    calculusTool.bSingleRun = false;
                    baseTool = calculusTool;
                    break;
                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机XYD数据工具:
                    LuxsanTool.Tool.XYDTool zakTool = new LuxsanTool.Tool.XYDTool(_strToolName);
                    zakTool.m_strToolName = _strToolName;
                    zakTool.m_bEnable = bEnable;
                    zakTool.m_strStationName = _strStationName;
                    zakTool.SetFilePath(m_strFilePath);
                    zakTool.Initial();
                    zakTool.bSingleRun = true;
                    //zakTool.RunTool();
                    zakTool.bSingleRun = false;
                    baseTool = zakTool;
                    break;
                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.弹窗工具:
                    LuxsanTool.Tool.PopFormTool popFormTool = new LuxsanTool.Tool.PopFormTool(_strToolName);
                    popFormTool.m_strToolName = _strToolName;
                    popFormTool.m_bEnable = bEnable;
                    popFormTool.m_strStationName = _strStationName;
                    popFormTool.SetFilePath(m_strFilePath);
                    popFormTool.Initial();
                    popFormTool.bSingleRun = true;
                    //popFormTool.RunTool();
                    popFormTool.bSingleRun = false;
                    baseTool = popFormTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具:
                    int a = 0;
                    //ScriptFactory scriptFactory = new ScriptFactory();
                    // _scriptFactory.IntialSriptEditor(m_strFilePath, strStationName, _strToolName);
                    string strError = "";
                    bool bError =false;
                    LuxsanTool.Tool.BaseTool other1BaseTool = _scriptFactory.CreateInstanceWithDll(m_strFilePath,strStationName, _strToolName, out strError);
                    //_scriptFactory.m_strScriptTxt = _scriptFactory.LoadTxt_Copy(m_strFilePath, strStationName, _strToolName, out bError);
                    other1BaseTool.m_strToolName = _strToolName;
                    other1BaseTool.m_bEnable = bEnable;
                    other1BaseTool.m_strStationName = strStationName;
                    other1BaseTool.SetFilePath(m_strFilePath);
                    other1BaseTool.Initial();
                    other1BaseTool.bSingleRun = true;
                    //_scriptFactory.m_other1BaseTool.AssistToolOutPutValue();
                    // _scriptFactory.m_other1BaseTool.RunTool();
                    //_scriptFactory.m_other1BaseTool.m_UserControl_Other1Tool.OutPutValueParaToForm();
                    other1BaseTool.bSingleRun = false;
                    //_scriptFactory.m_other1BaseTool.DisRunResult();
                    baseTool = other1BaseTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.备用工具2:
                    LuxsanTool.Tool.Other2Tool other2Tool = new LuxsanTool.Tool.Other2Tool(_strToolName);
                    other2Tool.m_strToolName = _strToolName;
                    other2Tool.m_bEnable = bEnable;
                    other2Tool.m_strStationName = _strStationName;
                    other2Tool.SetFilePath(m_strFilePath);
                    other2Tool.Initial();
                    other2Tool.bSingleRun = true;
                    //other2Tool.RunTool();
                    other2Tool.bSingleRun = false;
                    baseTool = other2Tool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机好帮手数据工具:
                    LuxsanTool.Tool.HaoBangShouTool haoBangShouTool = new LuxsanTool.Tool.HaoBangShouTool(_strToolName);
                    haoBangShouTool.m_strToolName = _strToolName;
                    haoBangShouTool.m_bEnable = bEnable;

                    haoBangShouTool.m_strStationName = _strStationName;
                    haoBangShouTool.SetFilePath(m_strFilePath);
                    haoBangShouTool.Initial();
                    haoBangShouTool.bSingleRun = true;
                    //haoBangShouTool.RunTool();
                    haoBangShouTool.bSingleRun = false;
                    baseTool = haoBangShouTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Taike数据工具:
                    LuxsanTool.Tool.TaikeTool taikeTool = new LuxsanTool.Tool.TaikeTool(_strToolName);
                    taikeTool.m_strToolName = _strToolName;
                    taikeTool.m_bEnable = bEnable;
                    taikeTool.m_strStationName = _strStationName;
                    taikeTool.SetFilePath(m_strFilePath);
                    taikeTool.Initial();
                    taikeTool.bSingleRun = true;
                    //taikeTool.RunTool();
                    taikeTool.bSingleRun = false;
                    baseTool = taikeTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.刷卡工具:
                    LuxsanTool.Tool.ReaderCardTool readerCardTool = new LuxsanTool.Tool.ReaderCardTool(_strToolName);
                    readerCardTool.m_strToolName = _strToolName;
                    readerCardTool.m_bEnable = bEnable;
                    readerCardTool.m_strStationName = _strStationName;
                    readerCardTool.SetFilePath(m_strFilePath);
                    readerCardTool.Initial();
                    readerCardTool.bSingleRun = true;
                    //taikeTool.RunTool();
                    readerCardTool.bSingleRun = false;
                    baseTool = readerCardTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.电脑性能监控工具:
                    LuxsanTool.Tool.ComputerResourceTool computerResourceTool = new LuxsanTool.Tool.ComputerResourceTool(_strToolName);
                    computerResourceTool.m_strToolName = _strToolName;
                    computerResourceTool.m_bEnable = bEnable;
                    computerResourceTool.m_strStationName = _strStationName;
                    computerResourceTool.SetFilePath(m_strFilePath);
                    computerResourceTool.Initial();
                    computerResourceTool.bSingleRun = true;
                    //computerResourceTool.RunTool();
                    computerResourceTool.bSingleRun = false;
                    baseTool = computerResourceTool;
                    break;

                case (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.CCTV工具:
                    LuxsanTool.Tool.CCTVTool cCTVTool = new LuxsanTool.Tool.CCTVTool(_strToolName);
                    cCTVTool.m_strToolName = _strToolName;
                    cCTVTool.m_bEnable = bEnable;
                    cCTVTool.m_strStationName = _strStationName;
                    cCTVTool.SetFilePath(m_strFilePath);
                    cCTVTool.Initial();
                    cCTVTool.bSingleRun = true;
                    //cCTVTool.RunTool();
                    cCTVTool.bSingleRun = false;
                    baseTool = cCTVTool;
                    break;
            }

            return baseTool;
        }
        #endregion

        #region  AddTool  添加工具(脚本工具和其他工具添加实例有差别)
        /// <summary>
        /// 添加工具(脚本工具和其他工具添加实例有差别)
        /// </summary>
        /// <param name="_strToolNmae"></param>
        /// <param name="_StationWork"></param>
        /// <returns></returns>
        public LuxsanBaseHelpLib.ExecuteStatus AddTool(string _strToolNmae, LuxsanTool.Tool.BaseTool _BaseTool, ScriptFactory _ScriptFactory)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();

            if (!m_mesBaseTool.Keys.Contains(_strToolNmae))
            {
                if (_BaseTool.m_EditId != (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具)
                {
                     m_mesBaseTool.Add(_strToolNmae, _BaseTool);
                    _BaseTool.m_strToolName = _strToolNmae;
                }
                else
                {
                    m_ScriptFactory.Add(_strToolNmae, _ScriptFactory);
                    //_BaseTool = m_ScriptFactory[_strToolNmae].m_other1BaseTool;
                    //_BaseTool.m_strToolName = _strToolNmae;
                    m_mesBaseTool.Add(_strToolNmae, _BaseTool);
                    
                }
                executeStatus.bStatus = true;
                executeStatus.strErrorMsg = "";
            }
            else
            {
                executeStatus.bStatus = false;
                executeStatus.strErrorMsg = "Work is Existed ";
            }

            return executeStatus;
        }
        #endregion

        #region  ModifyTool 调整工具
        /// <summary>
        /// 调整工具
        /// </summary>
        /// <param name="_strStationNmae"></param>
        /// <param name="_StationWork"></param>
        /// <returns></returns>
        public LuxsanBaseHelpLib.ExecuteStatus ModifyTool(string _strNewName, string _strOldName)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();

            if (m_mesBaseTool.Keys.Contains(_strOldName))
            {
                m_mesBaseTool = m_mesBaseTool.ToDictionary(k => k.Key == _strOldName ? _strNewName : k.Key, k => k.Value);
                m_mesBaseTool[_strNewName].m_strToolName = _strNewName;

                m_ScriptFactory = m_ScriptFactory.ToDictionary(k => k.Key == _strOldName ? _strNewName : k.Key, k => k.Value);


                executeStatus.bStatus = true;
                executeStatus.strErrorMsg = "";


            }
            else
            {
                executeStatus.bStatus = false;
                executeStatus.strErrorMsg = "Work is Existed ";
            }

            return executeStatus;
        }
        #endregion

        #region DeleteTool 删除工具
        /// <summary>
        /// 删除工具
        /// </summary>
        /// <param name="_strStationName"></param>
        /// <returns></returns>
        public LuxsanBaseHelpLib.ExecuteStatus DeleteTool(string _strToolName)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();
            if (m_mesBaseTool.Keys.Contains(_strToolName))
            {

                //删除工站
                m_mesBaseTool[_strToolName].Realse();
                m_mesBaseTool.Remove(_strToolName);

                m_ScriptFactory.Remove(_strToolName);

                executeStatus.bStatus = true;
                executeStatus.strErrorMsg = "";
            }
            else
            {
                executeStatus.bStatus = false;
                executeStatus.strErrorMsg = "Work is  No Existed ";
            }
            return executeStatus;
        }
        #endregion

    

        #region ModifyStationConfigName 调整工站名
        /// <summary>
        /// 修改引用此工站的对应工站名称
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void ModifyStationConfigName(string _strNewStationName, string _strOldStationName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.ModifyStationConfigName(_strNewStationName, _strOldStationName);
                if (baseTool.Value.m_strStationName== _strOldStationName)
                    baseTool.Value.m_strStationName = _strNewStationName;
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion

        #region DeleteStationConfigName 删除工站名
        /// <summary>
        /// 删除引用此工站的对应工站名称
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void DeleteStationConfigName(string _strDeleteStationName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.DeleteStationConfigName(_strDeleteStationName);
                //baseTool.Value.m_strStationName = "";
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion


        #region ModifyToolConfigName 调整工具名
        /// <summary>
        /// 修改引用此工具的对应工具名称
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void ModifyToolConfigName(string _strCurrentStation, string _strNewToolName, string _strOldToolName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.ModifyToolConfigName(_strCurrentStation,_strNewToolName, _strOldToolName);
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion

        #region DeleteToolConfigName 删除工具名
        /// <summary>
        /// 删除引用此工具的对应工具名称
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void DeleteToolConfigName(string _strCurrentStation, string _strDeleteToolName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.DeleteToolConfigName(_strCurrentStation,_strDeleteToolName);
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion


        #region ModifyComConfigName 调整引用通讯名 (调整通讯名的时候调用)
        /// <summary>
        /// 调整引用通讯名 (调整通讯名的时候调用)
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void ModifyComConfigName(string _strNewComName, string _strOldComName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.ModifyComConfigName(_strNewComName, _strOldComName);
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion

        #region DeleteComConfigName 删除引用通讯名 (调整通讯名的时候调用)
        /// <summary>
        /// 删除引用通讯名 (调整通讯名的时候调用)
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void DeleteComConfigName(string _strDeleteComName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.DeleteComConfigName(_strDeleteComName);
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion


        #region ModifyValueConfigName  调整引用获取值(输出值改变)   反调引用
        /// <summary>
        /// 修 调整引用获取值(输出值改变)   反调引用
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void ModifyValueConfigName(string _strCurStation, string _strCurTool,string _strNewValueName, string _strOldValueName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.ModifyValueConfigName(_strCurStation, _strCurTool,_strNewValueName, _strOldValueName);
                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion

        #region DeleteValueConfigName 删除引用获取值(输出值改变)   反调引用
        /// <summary>
        /// 删除引用获取值(输出值改变)   反调引用
        /// </summary>
        /// <param name="_strNewStationName"></param>
        /// <param name="_strOldStationName"></param>
        public void DeleteValueConfigName(string _strDeleteValueName)
        {
            foreach (KeyValuePair<string, BaseTool> baseTool in m_mesBaseTool)
            {
                baseTool.Value.DeleteValueConfigName(_strDeleteValueName);

                baseTool.Value.ModifiedDisToForm();

            }
        }
        #endregion


        #region  UpTool 上调
        /// <summary>
        /// 上调
        /// </summary>
        /// <param name="_strStationNmae"></param>
        /// <param name="_StationWork"></param>
        /// <returns></returns>
        public LuxsanBaseHelpLib.ExecuteStatus UpTool(string _strmoveToolName)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();

            if (m_mesBaseTool.Keys.Contains(_strmoveToolName))
            {

                List<string> listKey = m_mesBaseTool.Keys.ToList();
                List<BaseTool> listbaseTool = m_mesBaseTool.Values.ToList();

                string key = _strmoveToolName;
                BaseTool baseTool = m_mesBaseTool[key];

                int index = listKey.IndexOf(key);

                listKey.Remove(key);
                listbaseTool.Remove(baseTool);

                listKey.Insert(index - 1, key);
                listbaseTool.Insert(index - 1, baseTool);

                m_mesBaseTool = listbaseTool.ToDictionary(basetool => basetool.m_strToolName);


                executeStatus.bStatus = true;
                executeStatus.strErrorMsg = "";


            }
            else
            {
                executeStatus.bStatus = false;
                executeStatus.strErrorMsg = "Work is Existed ";
            }

            return executeStatus;
        }
        #endregion

        #region  DownTool 下调
        /// <summary>
        /// 上调
        /// </summary>
        /// <param name="_strStationNmae"></param>
        /// <param name="_StationWork"></param>
        /// <returns></returns>
        public LuxsanBaseHelpLib.ExecuteStatus DownTool(string _strmoveToolName)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();

            if (m_mesBaseTool.Keys.Contains(_strmoveToolName))
            {

                List<string> listKey = m_mesBaseTool.Keys.ToList();
                List<BaseTool> listbaseTool = m_mesBaseTool.Values.ToList();

                string key = _strmoveToolName;
                BaseTool baseTool = m_mesBaseTool[key];

                int index = listKey.IndexOf(key);

                listKey.Remove(key);
                listbaseTool.Remove(baseTool);

                listKey.Insert(index + 1, key);
                listbaseTool.Insert(index + 1, baseTool);

                m_mesBaseTool = listbaseTool.ToDictionary(basetool => basetool.m_strToolName);


                executeStatus.bStatus = true;
                executeStatus.strErrorMsg = "";


            }
            else
            {
                executeStatus.bStatus = false;
                executeStatus.strErrorMsg = "Work is Existed ";
            }

            return executeStatus;
        }
        #endregion

        #region  BaseToolContainRunState 是否包含运行状态
        /// <summary>
        ///  BaseToolContainRunState 是否包含运行状态
        /// </summary>
        /// <returns></returns>
        public bool BaseToolContainRunState()
        {
            bool bContainRunState = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行状态工具)
                {
                    bContainRunState = true;
                }
            }
            return bContainRunState;
        }
        #endregion

        #region  BaseToolContainRunMode  是否包含运行模式
        /// <summary>
        /// BaseToolContainRunMode 是否包含运行模式
        /// </summary>
        /// <returns></returns>
        public bool BaseToolContainRunMode()
        {
            bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行模式工具)
                {
                    bContainRunMode = true;
                }
            }
            return bContainRunMode;
        }
        #endregion

        #region  BaseToolContainCard  是否包含刷卡
        /// <summary>
        /// BaseToolContainCard 是否包含刷卡
        /// </summary>
        /// <returns></returns>
        public bool BaseToolContainCard()
        {
            bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.刷卡工具)
                {
                    bContainRunMode = true;
                }
            }
            return bContainRunMode;
        }
        #endregion

        #region  BaseToolContainHiveAll  是否包含HiveALL
        /// <summary>
        /// BaseToolContainHiveAll 是否包含HiveALL
        /// </summary>
        /// <returns></returns>
        public bool BaseToolContainHiveAll()
        {
            bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.Hive汇总工具)
                {
                    bContainRunMode = true;
                }
            }
            return bContainRunMode;
        }
        #endregion

        #region  BaseToolContainComputer  是否包含电脑资源
        /// <summary>
        /// BaseToolContainComputer 是否包含电脑资源
        /// </summary>
        /// <returns></returns>
        public bool BaseToolContainComputer()
        {
            bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.电脑性能监控工具)
                {
                    bContainRunMode = true;
                }
            }
            return bContainRunMode;
        }
        #endregion


        #region  BaseToolContainRunMode  是否包含运行模式
        /// <summary>
        /// BaseToolContainRunMode 是否包含运行模式
        /// </summary>
        /// <returns></returns>
        public void BaseToolContainPDCA()
        {
            //bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.PDCA工具)
                {
                    Tool.PDCATool pDCATool = mesToolBaseTool[i] as Tool.PDCATool;
                     pDCATool.GetStation();
                }
            }
            //return bContainRunMode;
        }
        #endregion

        #region  BaseToolContainRunMode  是否包含运行模式
        /// <summary>
        /// BaseToolContainRunMode 是否包含运行模式
        /// </summary>
        /// <returns></returns>
        public bool BaseToolLog()
        {
            //bool bContainRunMode = false;
            List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
            List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();
            for (int i = 0; i < mesToolBaseTool.Count; i++)
            {
                if (mesToolBaseTool[i].m_bLogEnable)
                {
                    return true;
                }
            }
            return false;
        }
        #endregion



        #region   StationProcess  动作流程
        /// <summary>
        /// 动作执行流程
        /// </summary>
        public override void StationProcess()
        {

     
            //int iStep = 0;
            int iRetry = 0;
            string strRunMsg = "";
            System.Diagnostics.Stopwatch stopwatchProcessimer = new System.Diagnostics.Stopwatch();
            while (bThreadWork)
            {
                //List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
                //List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();

                string stationName = this.strStationName;
                this.m_strLogName = this.strStationName;

                if (this.bPause|| !this.bStart)
                    BaseToolContainPDCA();

                if (this.bPause && !bSingleRun && !stationName.Contains("心跳")&&
                    !BaseToolContainRunState() && !BaseToolContainRunMode() && !BaseToolContainCard() && !BaseToolContainComputer()&&!BaseToolContainHiveAll())
                {
                    Thread.Sleep(500);
                    continue;
                }

                //!BaseToolContainRunState()
               // !BaseToolContainRunMode()
                if (!this.bStart && !bSingleRun && !stationName.Contains("心跳") &&
                    !BaseToolContainRunState()&& !BaseToolContainRunMode()&& !BaseToolContainCard()&& !BaseToolContainComputer() && !BaseToolContainHiveAll())
                {
                    Thread.Sleep(500);
                    continue;
                }

                if (!this.bEnable && !bSingleRun)
                {
                    luxsanStationWorkDelegate("Step", m_strLogName, strStationName, $"{stationName}:使能未打开");
                    Thread.Sleep(500);
                    continue;
                }

                if (!m_bInitial)
                {
                    m_bInitial = true;
                    AddLog(m_strLogName, "流程第一次运行~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", true);
                }

                List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
                List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();

                var tooltemp = mesToolBaseTool.Where(a => (a.bSingleRun = bSingleRun)).ToList();

                if (tooltemp.Count > 0)
                    mesToolBaseTool = tooltemp;

                if(mesToolBaseTool.Count<3)
                {
                    Thread.Sleep(1000);
                }

                int i = 0;
                //遍历工具
                for (i = 0; i < mesToolBaseTool.Count; i++)
                {

                    //if (!(mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.PDCA工具 ||
                    //      mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.MES工具))
                    //{
                    //    BaseToolContainPDCA();
                    //}

                    if (i==0|| i == 1)
                    {
                        BaseToolContainPDCA();
                        stopwatchProcessimer.Restart();
                    }

                    strCurToolName = mesToolBaseTool[i].m_strToolName;
                    luxsanStationWorkDelegate("Step", m_strLogName, strStationName, strCurToolName);

                    if (mesToolBaseTool.Count!= m_mesBaseTool.Values.Count)
                    {
                        Thread.Sleep(20);
                        break;
                    }
                   //if(stationName.Contains("出站"))
                   // {

                   // }

                    //LOG统一路径
                    mesToolBaseTool[i].m_strLogName = this.m_strLogName;

                    #region  定义变量工具

                    if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.定义变量工具)

                    {
                        
                        //工具转换
                        LuxsanTool.Tool.InstanceVarTool instanceVarTool = (LuxsanTool.Tool.InstanceVarTool)mesToolBaseTool[i];

                        instanceVarTool.m_stopwatchToolRunTimerAll.Restart();
                        instanceVarTool.m_executeStatus = instanceVarTool.RunTool();
                        instanceVarTool.DisRunResult();

                        //instanceVarTool.AssistToolOutPutValue();
                        //instanceVarTool.m_userControl_InstanceVarTool.OutPutValueParaToForm();

                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        instanceVarTool.m_stopwatchToolRunTimerAll.Stop();
                    }

                    #endregion

                    #region 判断工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.判断工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.JudgeTool ifTool = (LuxsanTool.Tool.JudgeTool)mesToolBaseTool[i];

                        ifTool.m_stopwatchToolRunTimerAll.Restart();
                        ifTool.m_executeStatus = ifTool.GetInPutValue();

                        int iFinishedSkip =0;
                        string strFinishedSkip = "";
                        //运行工具
                        if (ifTool.m_executeStatus.bStatus)
                        {
                            ifTool.m_executeStatus = ifTool.RunTool(out strFinishedSkip);
                        }
                        ifTool.DisRunResult();
                        //ifTool.AssistToolOutPutValue();
                        //ifTool.OutPutValueParaToForm();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");


                        iFinishedSkip= mesToolBaseTool.FindIndex(a=>a.m_strToolName== strFinishedSkip);
                        if (iFinishedSkip < 0)
                            iFinishedSkip = 0;
                        //for (int I = 0; I < mesToolBaseTool.Count; I++)
                        //{
                        //    if (mesToolBaseTool[I].m_strToolName == strFinishedSkip)
                        //        iFinishedSkip = I;
                        //}
                        int ijudgecount= ifTool.GetJudgeCount();
                        if (!bSingleRun&& ijudgecount>0)
                           i = iFinishedSkip-1;
                        Thread.Sleep(10);
                        //Thread.Sleep(5);
                        ifTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  分割字符串
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.字符操作工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.StrSpiltTool strSpiltTool = (LuxsanTool.Tool.StrSpiltTool)mesToolBaseTool[i];
                        strSpiltTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        strSpiltTool.m_executeStatus = strSpiltTool.GetInPutValue();
                        //运行工具
                        if (strSpiltTool.m_executeStatus.bStatus)
                            strSpiltTool.m_executeStatus = strSpiltTool.RunTool();

                        strSpiltTool.DisRunResult();
                        //strSpiltTool.AssistToolOutPutValue();
                        //strSpiltTool.m_userControl_InstanceVarTool.OutPutValueParaToForm();

                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        strSpiltTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region 根据索引获得数组值

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.获取数组值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ArraryContentTool arraryContentTool = (LuxsanTool.Tool.ArraryContentTool)mesToolBaseTool[i];
                        arraryContentTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        arraryContentTool.m_executeStatus = arraryContentTool.GetInPutValue();
                        //运行工具
                        if (arraryContentTool.m_executeStatus.bStatus)
                            arraryContentTool.m_executeStatus = arraryContentTool.RunTool();

                        arraryContentTool.DisRunResult();
                        //arraryContentTool.AssistToolOutPutValue();
                        //arraryContentTool.m_userControl_InstanceVarTool.OutPutValueParaToForm();

                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        arraryContentTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  通讯读取

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取通讯值工具)
                    {   //工具转换
                        LuxsanTool.Tool.ComReadValueTool comReadValueTool = (LuxsanTool.Tool.ComReadValueTool)mesToolBaseTool[i];
                        comReadValueTool.m_stopwatchToolRunTimerAll.Restart();
                        comReadValueTool.m_executeStatus = comReadValueTool.RunTool();
                        comReadValueTool.DisRunResult();
                        //comReadValueTool.AssistToolOutPutValue();
                        //comReadValueTool.m_userControl_InstanceVarTool.OutPutValueParaToForm();

                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        comReadValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  通讯发送
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入通讯值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ComWriteValueTool comWriteValueTool = (LuxsanTool.Tool.ComWriteValueTool)mesToolBaseTool[i];
                        comWriteValueTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        comWriteValueTool.m_executeStatus = comWriteValueTool.GetInPutValue();

                        if (comWriteValueTool.m_executeStatus.bStatus)
                            comWriteValueTool.m_executeStatus = comWriteValueTool.RunTool();

                        comWriteValueTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        comWriteValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  读取寄存器
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取PLC寄存器值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PLCReadValueTool pLCReadValueTool = (LuxsanTool.Tool.PLCReadValueTool)mesToolBaseTool[i];
                        pLCReadValueTool.m_stopwatchToolRunTimerAll.Restart();
                        pLCReadValueTool.m_executeStatus = pLCReadValueTool.RunTool();

                        pLCReadValueTool.DisRunResult();
                        mesToolBaseTool[i].m_executeStatus = pLCReadValueTool.m_executeStatus;
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        pLCReadValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region 写入寄存器
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入PLC寄存器值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PLCWriteValueTool pLCWriteValueTool = (LuxsanTool.Tool.PLCWriteValueTool)mesToolBaseTool[i];
                        pLCWriteValueTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        pLCWriteValueTool.m_executeStatus = pLCWriteValueTool.GetInPutValue();
                        if (pLCWriteValueTool.m_executeStatus.bStatus)
                            pLCWriteValueTool.m_executeStatus = pLCWriteValueTool.RunTool();
                        pLCWriteValueTool.DisRunResult();
                        mesToolBaseTool[i].m_executeStatus = pLCWriteValueTool.m_executeStatus;
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        pLCWriteValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  图表工具

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.图表显示工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ChartTool chartTool = (LuxsanTool.Tool.ChartTool)mesToolBaseTool[i];
                        chartTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        chartTool.m_executeStatus = chartTool.GetInPutValue();

                        if (chartTool.m_executeStatus.bStatus)
                            chartTool.m_executeStatus = chartTool.RunTool();

                        chartTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        chartTool.m_stopwatchToolRunTimerAll.Stop();


                    }
                    #endregion

                    #region MES

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.MES工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.MesTool mesTool = (LuxsanTool.Tool.MesTool)mesToolBaseTool[i];
                        mesTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        mesTool.m_executeStatus = mesTool.GetInPutValue();
                        if (mesTool.m_executeStatus.bStatus)
                            mesTool.m_executeStatus = mesTool.RunTool();
                        mesTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        mesTool.m_stopwatchToolRunTimerAll.Stop();

                    }

                    #endregion

                    #region  PDCA
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.PDCA工具)
                    {
                      
                        //工具转换
                        LuxsanTool.Tool.PDCATool pdcaTool = (LuxsanTool.Tool.PDCATool)mesToolBaseTool[i];
                        pdcaTool.m_stopwatchToolRunTimerAll.Restart();
                       

                        //获得输入值
                        pdcaTool.m_executeStatus = pdcaTool.GetInPutValue();

                                if (pdcaTool.m_executeStatus.bStatus)
                                    pdcaTool.m_executeStatus = pdcaTool.RunTool();
                                pdcaTool.DisRunResult();
                                luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                       
                        pdcaTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region Hive

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.HIVE工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.HiveTool hiveTool = (LuxsanTool.Tool.HiveTool)mesToolBaseTool[i];
                        //获得输入值

                        hiveTool.m_stopwatchToolRunTimerAll.Restart();
                        hiveTool.m_executeStatus = hiveTool.GetInPutValue();
                        if (hiveTool.m_executeStatus.bStatus)
                            hiveTool.m_executeStatus = hiveTool.RunTool();
                        hiveTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        hiveTool.m_stopwatchToolRunTimerAll.Stop();

                    }

                    #endregion

                    #region  文件操作工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.文件操作工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.SaveCsvTool saveCsvTool = (LuxsanTool.Tool.SaveCsvTool)mesToolBaseTool[i];
                        //获得输入值
                        saveCsvTool.m_stopwatchToolRunTimerAll.Restart();
                        saveCsvTool.m_executeStatus = saveCsvTool.GetInPutValue();
                        if (saveCsvTool.m_executeStatus.bStatus)
                            saveCsvTool.m_executeStatus = saveCsvTool.RunTool();
                        saveCsvTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        saveCsvTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  弹窗工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.弹窗工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PopFormTool popFormTool = (LuxsanTool.Tool.PopFormTool)mesToolBaseTool[i];
                        //获得输入值
                        popFormTool.m_stopwatchToolRunTimerAll.Restart();
                        popFormTool.m_executeStatus = popFormTool.GetInPutValue();
                        if (popFormTool.m_executeStatus.bStatus)
                            popFormTool.m_executeStatus = popFormTool.RunTool();
                        popFormTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        popFormTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  写入数据库
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入数据库工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.WriteDataBaseTool writeDataBaseTool = (LuxsanTool.Tool.WriteDataBaseTool)mesToolBaseTool[i];
                        writeDataBaseTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        writeDataBaseTool.m_executeStatus = writeDataBaseTool.GetInPutValue();
                        if (writeDataBaseTool.m_executeStatus.bStatus)
                            writeDataBaseTool.m_executeStatus = writeDataBaseTool.RunTool();
                        writeDataBaseTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        writeDataBaseTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  读取数据库
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取数据库工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ReadDataBaseTool readDataBaseBool = (LuxsanTool.Tool.ReadDataBaseTool)mesToolBaseTool[i];
                        readDataBaseBool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        readDataBaseBool.m_executeStatus = readDataBaseBool.GetInPutValue();
                        if (readDataBaseBool.m_executeStatus.bStatus)
                            readDataBaseBool.m_executeStatus = readDataBaseBool.RunTool();
                        readDataBaseBool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        readDataBaseBool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  运行状态
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行状态工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.RunStateTool runStateTool = (LuxsanTool.Tool.RunStateTool)mesToolBaseTool[i];
                        runStateTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        runStateTool.m_executeStatus = runStateTool.GetInPutValue();
                        if (runStateTool.m_executeStatus.bStatus)
                            runStateTool.m_executeStatus = runStateTool.RunTool();
                        runStateTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        runStateTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  运行模式
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行模式工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.RunModeTool runModeTool = (LuxsanTool.Tool.RunModeTool)mesToolBaseTool[i];
                        runModeTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        runModeTool.m_executeStatus = runModeTool.GetInPutValue();
                        if (runModeTool.m_executeStatus.bStatus)
                            runModeTool.m_executeStatus = runModeTool.RunTool();
                        runModeTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        runModeTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  赋值变量
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.赋值变量工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ValuationTool valuationTool = (LuxsanTool.Tool.ValuationTool)mesToolBaseTool[i];
                        valuationTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        valuationTool.m_executeStatus = valuationTool.GetInPutValue();
                        if (valuationTool.m_executeStatus.bStatus)
                            valuationTool.m_executeStatus = valuationTool.RunTool();
                        valuationTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        valuationTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  HiveErrorData
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.Hive汇总工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.HiveAllTool hiveMachineSateOrErrorDataTool = (LuxsanTool.Tool.HiveAllTool)mesToolBaseTool[i];
                        hiveMachineSateOrErrorDataTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        hiveMachineSateOrErrorDataTool.m_executeStatus = hiveMachineSateOrErrorDataTool.GetInPutValue();
                        if (hiveMachineSateOrErrorDataTool.m_executeStatus.bStatus)
                            hiveMachineSateOrErrorDataTool.m_executeStatus = hiveMachineSateOrErrorDataTool.RunTool();
                        hiveMachineSateOrErrorDataTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        hiveMachineSateOrErrorDataTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机Atlas
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Atlas数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.AtlasTool atlasTool = (LuxsanTool.Tool.AtlasTool)mesToolBaseTool[i];
                        atlasTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //atlasTool.m_executeStatus = atlasTool.GetInPutValue();
                        //if (atlasTool.m_executeStatus.bStatus)
                        atlasTool.m_executeStatus = atlasTool.RunTool();
                        atlasTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        atlasTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机XYD
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机XYD数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.XYDTool zakTool = (LuxsanTool.Tool.XYDTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机好帮手
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机好帮手数据工具)

                    {
                        //工具转换
                        LuxsanTool.Tool.HaoBangShouTool zakTool = (LuxsanTool.Tool.HaoBangShouTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机Taike
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Taike数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.TaikeTool zakTool = (LuxsanTool.Tool.TaikeTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  脚本编辑工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.Other1BaseTool other1Tool = (LuxsanTool.Tool.Other1BaseTool)mesToolBaseTool[i];
                        other1Tool.m_stopwatchToolRunTimerAll.Restart();
                        // string cc =other1Tool.m_ToolInputValue["工具名称"].objValue.ToString();
                        //获得输入值
                        for (int j = 0; j < 3; j++)
                        {
                            other1Tool.m_executeStatus = other1Tool.GetInPutValue();
                            if (other1Tool.m_executeStatus.bStatus)
                                break;
                        }
                        //在脚本里面设定工具参数，界面刷新  -----由于脚本每次编译生成新的类 原参数会被保存 运行时才能正确显示
                        other1Tool.m_UserControl_Other1Tool.SetParaToForm();
                        other1Tool.m_UserControl_Other1Tool.InPutValueParaToForm();
                        if (other1Tool.m_executeStatus.bStatus)
                         {
                            try
                            {
                                other1Tool.m_executeStatus = other1Tool.RunTool();
                            }
                            catch(Exception ex)
                            {
                                other1Tool.m_executeStatus.bStatus = false;
                                other1Tool.m_executeStatus.strErrorMsg = ex.Message;
                                other1Tool.SaveLog("【" + other1Tool.m_strToolName + "】 " + other1Tool.m_executeStatus.strErrorMsg, _bDisForm: true);
                            }
                        }
                        else
                        {
                            other1Tool.SaveLog("【" + other1Tool.m_strToolName + "】 获取脚本输入值失败 "+other1Tool.m_executeStatus.strErrorMsg, _bDisForm: true);
                        }
                        other1Tool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        other1Tool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  其他2
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.备用工具2)
                    {
                        //工具转换
                        LuxsanTool.Tool.Other2Tool other2Tool = (LuxsanTool.Tool.Other2Tool)mesToolBaseTool[i];
                        other2Tool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //other2Tool.m_executeStatus = other2Tool.GetInPutValue();
                        //if (other2Tool.m_executeStatus.bStatus)
                        other2Tool.m_executeStatus = other2Tool.RunTool();
                        other2Tool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        other2Tool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  刷卡
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.刷卡工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ReaderCardTool readerCardTool = (LuxsanTool.Tool.ReaderCardTool)mesToolBaseTool[i];
                        readerCardTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值

                        //readerCardTool.m_executeStatus = readerCardTool.GetInPutValue();
                        //if (readerCardTool.m_executeStatus.bStatus)
                        readerCardTool.m_executeStatus = readerCardTool.RunTool();
                        readerCardTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        readerCardTool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  电脑性能监控工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.电脑性能监控工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ComputerResourceTool computerResourceTool = (LuxsanTool.Tool.ComputerResourceTool)mesToolBaseTool[i];
                        //获得输入值
                        computerResourceTool.m_stopwatchToolRunTimerAll.Restart();
                        //computerResourceTool.m_executeStatus = computerResourceTool.GetInPutValue();
                        //if (computerResourceTool.m_executeStatus.bStatus)
                        computerResourceTool.m_executeStatus = computerResourceTool.RunTool();
                        computerResourceTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        computerResourceTool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  CCTV工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.CCTV工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.CCTVTool cCTVTool = (LuxsanTool.Tool.CCTVTool)mesToolBaseTool[i];
                        //获得输入值
                        cCTVTool.m_stopwatchToolRunTimerAll.Restart();
                        cCTVTool.m_executeStatus = cCTVTool.GetInPutValue();
                        if (cCTVTool.m_executeStatus.bStatus)
                            cCTVTool.m_executeStatus = cCTVTool.RunTool();
                        cCTVTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        cCTVTool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  产能显示工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.产能显示工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ProductTool productTool = (LuxsanTool.Tool.ProductTool)mesToolBaseTool[i];
                        productTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        productTool.m_executeStatus = productTool.GetInPutValue();
                        if (productTool.m_executeStatus.bStatus)
                            productTool.m_executeStatus = productTool.RunTool();
                        productTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        productTool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    #region  逻辑运算
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.逻辑运算工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.CalculusTool calculusTool = (LuxsanTool.Tool.CalculusTool)mesToolBaseTool[i];
                        calculusTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        calculusTool.m_executeStatus = calculusTool.GetInPutValue();
                        if (calculusTool.m_executeStatus.bStatus)
                            calculusTool.m_executeStatus = calculusTool.RunTool();
                        calculusTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        calculusTool.m_stopwatchToolRunTimerAll.Stop();
                    }
                    #endregion

                    Thread.Sleep(5);
                }

                long timerall = (mesToolBaseTool.Select(a => a.GetRunTimer()).ToList()).Sum();
                long timerall_1 = (mesToolBaseTool.Select(a => a.GetRunTimer_1()).ToList()).Sum();
                stopwatchProcessimer.Stop();
                luxsanStationWorkDelegate("Timer", m_strLogName, strStationName,(timerall / 1000.0f).ToString());
                luxsanStationWorkDelegate("Timer_log", m_strLogName, strStationName, (timerall_1 / 1000.0f).ToString());
                luxsanStationWorkDelegate("Timer_all", m_strLogName, strStationName, (stopwatchProcessimer.ElapsedMilliseconds / 1000.0f).ToString());

                bSingleRun = false;
                mesToolBaseTool = mesToolBaseTool.Where(a => (a.bSingleRun = bSingleRun)).ToList();
                if (BaseToolLog())
                {
                    AddLog(m_strLogName, "流程耗时_工具运行(s):" + (timerall / 1000.0f), true) ;
                    AddLog(m_strLogName, "流程耗时_工具运行加LOG(s):" + (timerall_1 / 1000.0f), true);
                    AddLog(m_strLogName, "流程耗时_all(s):" + (stopwatchProcessimer.ElapsedMilliseconds / 1000.0f), true);
                    AddLog(m_strLogName, " ************************************* ",true);
                }
                mesToolBaseTool.ForEach(a => a.ClearRunTimer());
              
                Thread.Sleep(10);
            }
        }
        #endregion

        #region   SonStationProcess  动作子执行流程
        /// <summary>
        /// 动作子执行流程
        /// </summary>
        public LuxsanBaseHelpLib.ExecuteStatus SonStationProcess(string _strLogName)
        {
            LuxsanBaseHelpLib.ExecuteStatus executeStatus = new LuxsanBaseHelpLib.ExecuteStatus();

            //int iStep = 0;
            int iRetry = 0;
            string strRunMsg = "";
            System.Diagnostics.Stopwatch stopwatchProcessimer = new System.Diagnostics.Stopwatch();


            while (bThreadWork)
            {
                //List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
                //List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();

                string stationName = this.strStationName;
                this.m_strLogName = _strLogName;
                //BaseToolContainPDCA();

                //if (this.bPause && !BaseToolContainRunMode() && !BaseToolContainRunState() && !bSingleRun)
                //{
                //    Thread.Sleep(100);
                //    continue;
                //}

                //if (!this.bStart && !BaseToolContainRunMode() && !BaseToolContainRunState() && !bSingleRun)
                //{
                //    Thread.Sleep(100);
                //    continue;
                //}

                //if (!this.bEnable && !bSingleRun)
                //{
                //    luxsanStationWorkDelegate("Step", stationName, $"{stationName}:使能未打开");
                //    Thread.Sleep(100);
                //    continue;
                //}



                List<string> mesToolKey = m_mesBaseTool.Keys.ToList();
                List<BaseTool> mesToolBaseTool = m_mesBaseTool.Values.ToList();

                var tooltemp = mesToolBaseTool.Where(a => (a.bSingleRun = bSingleRun)).ToList();

                if (tooltemp.Count > 0)
                    mesToolBaseTool = tooltemp;

               

                int i = 0;
                //遍历工具
                for (i = 0; i < mesToolBaseTool.Count; i++)
                {

                    strCurToolName = mesToolBaseTool[i].m_strToolName;
                    luxsanStationWorkDelegate("Step", m_strLogName, strStationName, strCurToolName);

                    if (mesToolBaseTool.Count != m_mesBaseTool.Values.Count)
                    {
                        Thread.Sleep(20);
                        break;
                    }
                    //LOG统一路径
                    mesToolBaseTool[i].m_strLogName=this.m_strLogName;

                    if (i == 0)
                    {
                        stopwatchProcessimer.Restart();
                    }


                    #region  定义变量工具

                    if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.定义变量工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.InstanceVarTool instanceVarTool = (LuxsanTool.Tool.InstanceVarTool)mesToolBaseTool[i];
                        instanceVarTool.m_stopwatchToolRunTimerAll.Restart();
                        instanceVarTool.m_executeStatus = instanceVarTool.RunTool();
                        instanceVarTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        instanceVarTool.m_stopwatchToolRunTimerAll.Stop();
                    }

                    #endregion

                    #region 判断工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.判断工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.JudgeTool ifTool = (LuxsanTool.Tool.JudgeTool)mesToolBaseTool[i];
                        ifTool.m_stopwatchToolRunTimerAll.Restart();
                        ifTool.m_executeStatus = ifTool.GetInPutValue();

                        int iFinishedSkip = 0;
                        string strFinishedSkip = "";
                        //运行工具
                        if (ifTool.m_executeStatus.bStatus)
                        {
                            ifTool.m_executeStatus = ifTool.RunTool(out strFinishedSkip);
                        }
                        ifTool.DisRunResult();

                       int ijudgecount= ifTool.GetJudgeCount();

                       

                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");

                        for (int I = 0; I < mesToolBaseTool.Count; I++)
                        {
                            if (mesToolBaseTool[I].m_strToolName == strFinishedSkip)
                                iFinishedSkip = I;
                        }

                        if (!bSingleRun && ijudgecount != 0)
                            i = iFinishedSkip - 1;

                        Thread.Sleep(10);
                        ifTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  分割字符串
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.字符操作工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.StrSpiltTool strSpiltTool = (LuxsanTool.Tool.StrSpiltTool)mesToolBaseTool[i];
                        strSpiltTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        strSpiltTool.m_executeStatus = strSpiltTool.GetInPutValue();
                        //运行工具
                        if (strSpiltTool.m_executeStatus.bStatus)
                            strSpiltTool.m_executeStatus = strSpiltTool.RunTool();

                        strSpiltTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        strSpiltTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region 根据索引获得数组值

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.获取数组值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ArraryContentTool arraryContentTool = (LuxsanTool.Tool.ArraryContentTool)mesToolBaseTool[i];
                        arraryContentTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        arraryContentTool.m_executeStatus = arraryContentTool.GetInPutValue();
                        //运行工具
                        if (arraryContentTool.m_executeStatus.bStatus)
                            arraryContentTool.m_executeStatus = arraryContentTool.RunTool();

                        arraryContentTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        arraryContentTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  通讯读取

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取通讯值工具)
                    {   //工具转换
                        LuxsanTool.Tool.ComReadValueTool comReadValueTool = (LuxsanTool.Tool.ComReadValueTool)mesToolBaseTool[i];
                        comReadValueTool.m_stopwatchToolRunTimerAll.Restart();
                        comReadValueTool.m_executeStatus = comReadValueTool.RunTool();
                        comReadValueTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        comReadValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  通讯发送
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入通讯值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ComWriteValueTool comWriteValueTool = (LuxsanTool.Tool.ComWriteValueTool)mesToolBaseTool[i];
                        comWriteValueTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        comWriteValueTool.m_executeStatus = comWriteValueTool.GetInPutValue();

                        if (comWriteValueTool.m_executeStatus.bStatus)
                            comWriteValueTool.m_executeStatus = comWriteValueTool.RunTool();

                        comWriteValueTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        comWriteValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  读取寄存器
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取PLC寄存器值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PLCReadValueTool pLCReadValueTool = (LuxsanTool.Tool.PLCReadValueTool)mesToolBaseTool[i];
                        pLCReadValueTool.m_stopwatchToolRunTimerAll.Restart();
                        pLCReadValueTool.m_executeStatus = pLCReadValueTool.RunTool();

                        pLCReadValueTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        pLCReadValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region 写入寄存器
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入PLC寄存器值工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PLCWriteValueTool pLCWriteValueTool = (LuxsanTool.Tool.PLCWriteValueTool)mesToolBaseTool[i];
                        pLCWriteValueTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        pLCWriteValueTool.m_executeStatus = pLCWriteValueTool.GetInPutValue();
                        if (pLCWriteValueTool.m_executeStatus.bStatus)
                            pLCWriteValueTool.m_executeStatus = pLCWriteValueTool.RunTool();
                        pLCWriteValueTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        pLCWriteValueTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  图表工具

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.图表显示工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ChartTool chartTool = (LuxsanTool.Tool.ChartTool)mesToolBaseTool[i];
                        chartTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        chartTool.m_executeStatus = chartTool.GetInPutValue();

                        if (chartTool.m_executeStatus.bStatus)
                            chartTool.m_executeStatus = chartTool.RunTool();

                        chartTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");

                        chartTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region MES

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.MES工具)

                    {
                        //工具转换
                        LuxsanTool.Tool.MesTool mesTool = (LuxsanTool.Tool.MesTool)mesToolBaseTool[i];
                        mesTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        mesTool.m_executeStatus = mesTool.GetInPutValue();
                        if (mesTool.m_executeStatus.bStatus)
                            mesTool.m_executeStatus = mesTool.RunTool();
                        mesTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        mesTool.m_stopwatchToolRunTimerAll.Stop();

                    }

                    #endregion

                    #region  PDCA
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.PDCA工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PDCATool pdcaTool = (LuxsanTool.Tool.PDCATool)mesToolBaseTool[i];
                        pdcaTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        pdcaTool.m_executeStatus = pdcaTool.GetInPutValue();
                        if (pdcaTool.m_executeStatus.bStatus)
                            pdcaTool.m_executeStatus = pdcaTool.RunTool();
                        pdcaTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        pdcaTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region Hive

                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.HIVE工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.HiveTool hiveTool = (LuxsanTool.Tool.HiveTool)mesToolBaseTool[i];
                        //获得输入值
                        hiveTool.m_stopwatchToolRunTimerAll.Restart();

                        hiveTool.m_executeStatus = hiveTool.GetInPutValue();
                        if (hiveTool.m_executeStatus.bStatus)
                            hiveTool.m_executeStatus = hiveTool.RunTool();
                        hiveTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        hiveTool.m_stopwatchToolRunTimerAll.Stop();

                    }

                    #endregion

                    #region  文件操作工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.文件操作工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.SaveCsvTool saveCsvTool = (LuxsanTool.Tool.SaveCsvTool)mesToolBaseTool[i];
                        //获得输入值
                        saveCsvTool.m_stopwatchToolRunTimerAll.Restart();
                        saveCsvTool.m_executeStatus = saveCsvTool.GetInPutValue();
                        if (saveCsvTool.m_executeStatus.bStatus)
                            saveCsvTool.m_executeStatus = saveCsvTool.RunTool();
                        saveCsvTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        saveCsvTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  弹窗工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.弹窗工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.PopFormTool popFormTool = (LuxsanTool.Tool.PopFormTool)mesToolBaseTool[i];
                        popFormTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值

                        popFormTool.m_executeStatus = popFormTool.GetInPutValue();
                        if (popFormTool.m_executeStatus.bStatus)
                            popFormTool.m_executeStatus = popFormTool.RunTool();
                        popFormTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        popFormTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  写入数据库
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.写入数据库工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.WriteDataBaseTool writeDataBaseTool = (LuxsanTool.Tool.WriteDataBaseTool)mesToolBaseTool[i];
                        writeDataBaseTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        writeDataBaseTool.m_executeStatus = writeDataBaseTool.GetInPutValue();
                        if (writeDataBaseTool.m_executeStatus.bStatus)
                            writeDataBaseTool.m_executeStatus = writeDataBaseTool.RunTool();
                        writeDataBaseTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName,$"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        writeDataBaseTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  读取数据库
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.读取数据库工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ReadDataBaseTool readDataBaseBool = (LuxsanTool.Tool.ReadDataBaseTool)mesToolBaseTool[i];
                        readDataBaseBool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        readDataBaseBool.m_executeStatus = readDataBaseBool.GetInPutValue();
                        if (readDataBaseBool.m_executeStatus.bStatus)
                            readDataBaseBool.m_executeStatus = readDataBaseBool.RunTool();
                        readDataBaseBool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        readDataBaseBool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  运行状态
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行状态工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.RunStateTool runStateTool = (LuxsanTool.Tool.RunStateTool)mesToolBaseTool[i];
                        runStateTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        runStateTool.m_executeStatus = runStateTool.GetInPutValue();
                        if (runStateTool.m_executeStatus.bStatus)
                            runStateTool.m_executeStatus = runStateTool.RunTool();
                        runStateTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        runStateTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  运行模式
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.运行模式工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.RunModeTool runModeTool = (LuxsanTool.Tool.RunModeTool)mesToolBaseTool[i];
                        runModeTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        runModeTool.m_executeStatus = runModeTool.GetInPutValue();
                        if (runModeTool.m_executeStatus.bStatus)
                            runModeTool.m_executeStatus = runModeTool.RunTool();
                        runModeTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        runModeTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  赋值变量
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.赋值变量工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ValuationTool valuationTool = (LuxsanTool.Tool.ValuationTool)mesToolBaseTool[i];
                        valuationTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        valuationTool.m_executeStatus = valuationTool.GetInPutValue();
                        if (valuationTool.m_executeStatus.bStatus)
                            valuationTool.m_executeStatus = valuationTool.RunTool();
                        valuationTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        valuationTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  HiveErrorData
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.Hive汇总工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.HiveAllTool hiveMachineSateOrErrorDataTool = (LuxsanTool.Tool.HiveAllTool)mesToolBaseTool[i];
                        hiveMachineSateOrErrorDataTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        hiveMachineSateOrErrorDataTool.m_executeStatus = hiveMachineSateOrErrorDataTool.GetInPutValue();
                        if (hiveMachineSateOrErrorDataTool.m_executeStatus.bStatus)
                            hiveMachineSateOrErrorDataTool.m_executeStatus = hiveMachineSateOrErrorDataTool.RunTool();
                        hiveMachineSateOrErrorDataTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        hiveMachineSateOrErrorDataTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机Atlas
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Atlas数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.AtlasTool atlasTool = (LuxsanTool.Tool.AtlasTool)mesToolBaseTool[i];
                        atlasTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //atlasTool.m_executeStatus = atlasTool.GetInPutValue();
                        //if (atlasTool.m_executeStatus.bStatus)
                        atlasTool.m_executeStatus = atlasTool.RunTool();
                        atlasTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");

                        atlasTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机Zak
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机XYD数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.XYDTool zakTool = (LuxsanTool.Tool.XYDTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        ////获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机好帮手
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机好帮手数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.HaoBangShouTool zakTool = (LuxsanTool.Tool.HaoBangShouTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  螺丝机Taike
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.螺丝机Taike数据工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.TaikeTool zakTool = (LuxsanTool.Tool.TaikeTool)mesToolBaseTool[i];
                        zakTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //zakTool.m_executeStatus = zakTool.GetInPutValue();
                        //if (zakTool.m_executeStatus.bStatus)
                        zakTool.m_executeStatus = zakTool.RunTool();
                        zakTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        zakTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  脚本编辑工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.脚本编辑工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.Other1BaseTool other1Tool = (LuxsanTool.Tool.Other1BaseTool)mesToolBaseTool[i];
                        other1Tool.m_stopwatchToolRunTimerAll.Restart();

                        //获得输入值
                        other1Tool.m_executeStatus = other1Tool.GetInPutValue();
                        other1Tool.m_UserControl_Other1Tool.SetParaToForm();
                        other1Tool.m_UserControl_Other1Tool.InPutValueParaToForm();

                        if (other1Tool.m_executeStatus.bStatus)
                        {
                            try
                            { 
                            other1Tool.m_executeStatus = other1Tool.RunTool();
                            }
                            catch (Exception ex)
                            {
                                other1Tool.m_executeStatus.bStatus = false;
                                other1Tool.m_executeStatus.strErrorMsg = ex.Message;
                            }
                        }

                        other1Tool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        other1Tool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  其他2
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.备用工具2)
                    {
                        //工具转换
                        LuxsanTool.Tool.Other2Tool other2Tool = (LuxsanTool.Tool.Other2Tool)mesToolBaseTool[i];
                        other2Tool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        //other2Tool.m_executeStatus = other2Tool.GetInPutValue();
                        //if (other2Tool.m_executeStatus.bStatus)
                        other2Tool.m_executeStatus = other2Tool.RunTool();
                        other2Tool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        other2Tool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  刷卡
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.刷卡工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ReaderCardTool readerCardTool = (LuxsanTool.Tool.ReaderCardTool)mesToolBaseTool[i];
                        readerCardTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值

                        readerCardTool.m_executeStatus = readerCardTool.GetInPutValue();
                        if (readerCardTool.m_executeStatus.bStatus)
                            readerCardTool.m_executeStatus = readerCardTool.RunTool();
                        readerCardTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        readerCardTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  电脑性能监控工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.电脑性能监控工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ComputerResourceTool computerResourceTool = (LuxsanTool.Tool.ComputerResourceTool)mesToolBaseTool[i];
                        computerResourceTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值

                        computerResourceTool.m_executeStatus = computerResourceTool.GetInPutValue();
                        if (computerResourceTool.m_executeStatus.bStatus)
                            computerResourceTool.m_executeStatus = computerResourceTool.RunTool();
                        computerResourceTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        computerResourceTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  CCTV工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.CCTV工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.CCTVTool cCTVTool = (LuxsanTool.Tool.CCTVTool)mesToolBaseTool[i];
                        cCTVTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值

                        cCTVTool.m_executeStatus = cCTVTool.GetInPutValue();
                        if (cCTVTool.m_executeStatus.bStatus)
                            cCTVTool.m_executeStatus = cCTVTool.RunTool();
                        cCTVTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        cCTVTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  产能显示工具
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.产能显示工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.ProductTool productTool = (LuxsanTool.Tool.ProductTool)mesToolBaseTool[i];
                        productTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        productTool.m_executeStatus = productTool.GetInPutValue();
                        if (productTool.m_executeStatus.bStatus)
                            productTool.m_executeStatus = productTool.RunTool();
                        productTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        productTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion

                    #region  逻辑运算
                    else if (mesToolBaseTool[i].m_EditId == (int)LuxsanTool.Tool.ToolEnum.ToolEditEnum.逻辑运算工具)
                    {
                        //工具转换
                        LuxsanTool.Tool.CalculusTool calculusTool = (LuxsanTool.Tool.CalculusTool)mesToolBaseTool[i];
                        calculusTool.m_stopwatchToolRunTimerAll.Restart();
                        //获得输入值
                        calculusTool.m_executeStatus = calculusTool.GetInPutValue();
                        if (calculusTool.m_executeStatus.bStatus)
                            calculusTool.m_executeStatus = calculusTool.RunTool();
                        calculusTool.DisRunResult();
                        luxsanStationWorkDelegate("Step", mesToolBaseTool[i].m_strLogName, strStationName, $"{strCurToolName}({(mesToolBaseTool[i].GetRunTimer() / 1000.0f).ToString()}s)");
                        calculusTool.m_stopwatchToolRunTimerAll.Stop();

                    }
                    #endregion


                    Thread.Sleep(5);
                }


                long timerall = (mesToolBaseTool.Select(a => a.GetRunTimer()).ToList()).Sum();
                long timerall_1 = (mesToolBaseTool.Select(a => a.GetRunTimer_1()).ToList()).Sum();
                stopwatchProcessimer.Stop();
                luxsanStationWorkDelegate("Timer", m_strLogName, strStationName, (timerall / 1000.0f).ToString());
                luxsanStationWorkDelegate("Timer_log", m_strLogName, strStationName, (timerall_1 / 1000.0f).ToString());
                luxsanStationWorkDelegate("Timer_all", m_strLogName, strStationName, (stopwatchProcessimer.ElapsedMilliseconds / 1000.0f).ToString());

                bSingleRun = false;
                mesToolBaseTool = mesToolBaseTool.Where(a => (a.bSingleRun = bSingleRun)).ToList();
                if (BaseToolLog())
                {
                    AddLog(m_strLogName, "流程耗时_工具运行(s):" + (timerall / 1000.0f), true);
                    AddLog(m_strLogName, "流程耗时_工具运行加LOG(s):" + (timerall_1 / 1000.0f), true);
                    AddLog(m_strLogName, "流程耗时_all(s):" + (stopwatchProcessimer.ElapsedMilliseconds / 1000.0f), true);
                    AddLog(m_strLogName, " ******************************************************* ",true);

                }
                
                bThreadWork = false;
                Thread.Sleep(10);
            }

            foreach (KeyValuePair<string, BaseTool> pair in  m_mesBaseTool)
            {
                executeStatus = pair.Value.m_executeStatus;
                if (!executeStatus.bStatus)
                {
                    break;
                }
            }

            return executeStatus;
        }
        #endregion

   

        #region AddLog 添加记录 （外面条用）
        string strMsg;
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name = "_strStationId" ></ param >
        /// < param name="_strRunMsg"></param>
        public override void AddLog(string _strLogName, string _strRunMsg, bool _bDisForm)
        {
            if (strMsg != "【" + this.strStationName + "】" + _strRunMsg)
            {
                if (_bDisForm)
                {
                    Task.Run(() =>
                  {
                      m_UserControl_Log.SetMessage(this.strStationName, "【" + this.strStationName + "】" + _strRunMsg);
                  });
                }
                strMsg = "【" + this.strStationName + "】" + _strRunMsg;
            }


            Task.Run(() =>
            {
                try
                {
                    //mutex.WaitOne();
                    if (_strLogName == "MESLog")
                    {
                        m_LogFile.WriteMESLog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);
                    }
                    else if (_strLogName == "PDCALog")
                    {
                        m_LogFile.WritePDCALog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);

                    }
                    else if (_strLogName == "HiveLog")
                    {
                        m_LogFile.WriteHiveLog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);
                    }
                    else if (_strLogName == "Alarm")
                    {
                        m_LogFile.WriteAlarmLog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);
                    }
                    else if (_strLogName == "ExceptionLog")
                    {
                        m_LogFile.WriteExceptionLog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);
                    }

                    m_LogFile.WriteRunningLog(_strLogName, "【" + this.strStationName + "】" + _strRunMsg);

                }
                catch (Exception ex)
                {
                    m_LogFile.WriteExceptionLog(_strLogName, "【" + this.strStationName + "】 记录日志异常：" + ex.Message);
                    m_LogFile.WriteRunningLog(_strLogName, "【" + this.strStationName + "】 记录日志异常：" + ex.Message);

                }
                //finally
                //{
                //    mutex.ReleaseMutex();
                //}
            });
        }
        #endregion

        #region Alarm 添加报警记录（外面条用）
        /// <summary>
        // / 添加报警记录
        // / </summary>
        /// <param name = "_iErrorCode" ></ param >
        /// < param name="_strStationId"></param>
        /// <param name = "_strRunMsg" ></ param >
        public override void Alarm(int _iErrorCode, string _strLogName, string _strRunMsg, bool _bDisForm)
        {
            AddLog(_strLogName, _strRunMsg, _bDisForm);

        }
        #endregion


    }
}


